package com.weiyi.mashangzhu.Landlord.Activity;

import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.widget.ImageView;

import com.weiyi.mashangzhu.Application.MyApp;
import com.weiyi.mashangzhu.Base.BaseActivity;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Utils.SPUtils;
import com.weiyi.mashangzhu.easemob.DemoHelper;
import com.weiyi.mashangzhu.easemob.DemoModel;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseActivity {
    boolean flag1=false;
    boolean flag2=false;
    @BindView(R.id.img_1)
    ImageView img1;
    @BindView(R.id.img_2)
    ImageView img2;
    private DemoModel settingsModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
        if (SPUtils.get(this,"voice","0").equals("0")){
            img1.setImageResource(R.mipmap.button21);
        }else {
            img1.setImageResource(R.mipmap.button);
        }
        if (SPUtils.get(this,"vibrato","0").equals("0")){
            img2.setImageResource(R.mipmap.button21);
        }else {
            img2.setImageResource(R.mipmap.button);
        }
        settingsModel = DemoHelper.getInstance().getModel();
    }

    @OnClick({R.id.back, R.id.img_1, R.id.img_2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.img_1:
                if (flag1 == false) {
                    img1.setImageResource(R.mipmap.button);
                    flag1=true;
                    settingsModel.setSettingMsgSound(true);
                    SPUtils.put(SettingActivity.this,"voice","1");
                }else {

                    img1.setImageResource(R.mipmap.button21);
                    flag1=false;
                    settingsModel.setSettingMsgSound(false);
                    SPUtils.put(SettingActivity.this,"voice","0");
                }
                break;
            case R.id.img_2:
                if (flag2 == false) {
                    img2.setImageResource(R.mipmap.button);
                    flag2=true;
                    settingsModel.setSettingMsgVibrate(true);
                    SPUtils.put(SettingActivity.this,"vibrato","1");
                }else {
                    img2.setImageResource(R.mipmap.button21);
                    flag2=false;
                    settingsModel.setSettingMsgVibrate(false);
                    SPUtils.put(SettingActivity.this,"vibrato","0");
                }
                break;
        }
    }
}
